#include "chooseapp.h"
#include "ui_choosapp.h"
#include <tools.h>

ChooseApp::ChooseApp (CenteredWidget *parent) :
    QDialog(parent),
    ui (new Ui::ChooseApp)
{
    ui->setupUi(this);
    setWindowTitle (Config::appName ());
    setWindowIcon (Config::appIcon ());

    ui->Ok->setIcon (QIcon::fromTheme ("window-close", QIcon (":/images/window-close.svg")));

    m_config = new Config (0);

    QList<AppInfo> wpList (Config::wordProcessors ());

    foreach (AppInfo info, wpList) {
        QListWidgetItem* item = new QListWidgetItem (info.icon (), info.name ());
        ui->appList->addItem (item);
    }

    ui->appList->setSelectionMode (QAbstractItemView::SingleSelection);
    ui->appList->setCurrentRow (m_config->optionWordProcessorIndex ());

    connect (ui->dontAskMe,
             SIGNAL(clicked(bool)),
             m_config,
             SLOT(setOptionDontAskForWP(bool)));

    connect (ui->appList,
             SIGNAL(currentRowChanged(int)),
             m_config,
             SLOT(setOptionWordProcessorIndex(int)));


    ui->dontAskMe->setChecked (false);
}
//-----------------------
ChooseApp::~ChooseApp()
{
    delete ui;
    delete m_config;
}
//-------------------------------------
void ChooseApp::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
    break;
    default:
    break;
    }
}
//-----------------------------
void ChooseApp::on_Ok_clicked()
{
    accept ();
}
